﻿using System.Collections.Generic;
using System.Linq;
using easyVal.ServerSide;
using easyVal.Web.Demo.Entities;

namespace easyVal.Web.Demo.BL
{
    public class EmployeeBL
    {
        public static void SaveEmployeeEasy(Employee employee)
        {
            //Validate
            List<ErrorInfo> errors = DataAnnotationsValidationRunner.GetErrors(employee);

            if (errors.Any())
            {
                throw new RulesException(errors);
            }

            //TODO: Save to database
        }

        public static void SaveEmployeeWithoutEasyval(Employee employee)
        {
            //Validate
            ValidateEmployee(employee);

            //TODO: Save to database
        }

        private static void ValidateEmployee(Employee employee)
        {
            if (employee.FirstName == null) {
                throw new RulesException("First Name is required.");               
            }
            if (employee.FirstName.Length > 15) {
                throw new RulesException("Maximum Length for First Name is 15");
            }
            if (employee.Email.Length > 100) {
                throw new RulesException("Maximum Length for Email is 100");
            }
            
            //[StringLengthVal(100, ErrorMessage = "Maximum Length for Email is 100")]
            //[Email(ErrorMessage = "Email is not Valid.")]
            //public string Email { get; set; }

            //[RequiredVal( ErrorMessage = "Desired Salary is required.")]
            //[RangeVal(1, int.MaxValue, ErrorMessage = "Desired Salary must be between 0 and 2.14 billion")]
            //public int DesiredSalary { get; set; }

            //[USPhone(ErrorMessage = "Must be 10 digits. Hypens or spaces are optional.")]
            //public string PhoneNumber { get; set; }


        }
    }
}